//
//  RequestData.m
//  Kids
//
//  Created by LiTengFei on 14/11/26.
//  Copyright (c) 2014年 90's Technology Co.Ltd. All rights reserved.
//

#import "RequestData.h"

@implementation RequestData

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.baseURL = @"http://114.215.169.134/chip/web/index.php";
    }
    return self;
}

- (NSString*)requestURL
{
    NSParameterAssert(self.baseURL);
    NSParameterAssert(self.r);
    NSString* str = [NSString
        stringWithFormat:@"%@?r=%@",self.baseURL,self.r];

    str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    return str;
}
-(NSDictionary *)requestParams{
    NSString * params = [self toJSONString:self.data];
    return  @{@"data":params};
}
- (NSString*)toJSONString:(NSDictionary*)dict
{
    NSParameterAssert(dict);

    NSError* error;
    NSData* jsonData =
        [NSJSONSerialization dataWithJSONObject:dict
                                        options:NSJSONWritingPrettyPrinted
                                          error:&error];
    NSString* str =
        [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    str = [NSString stringWithFormat:@"%@", str];
    return str;
}
@end
